﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace VRacer.Packets
{
    /// <summary>
    /// Definiuje pakiet przesylany miedzy instancjami gry sieciowej.
    /// </summary>
    public abstract class PacketBase : IPacket
    {

        private PacketType _type;
        private int _length;

        public PacketBase(PacketType type)
        {
            _type = type;
            Length = 0;
        }
        /// <summary>
        /// Dlugosc pakietu w bajtach
        /// </summary>
        /// <value>The length.</value>
        public virtual int Length
        {
            get { return _length; }
            set { _length = value; }
        }

        public PacketType Type
        {
            get { return _type; }
        }

        /// <summary>
        /// Wczytuje zawartosc pakietu ze strumienia wejsciowego
        /// </summary>
        public void Read(Stream input)
        {
            Read(new BinaryReader(input));
        }

        public virtual void Read(BinaryReader reader)
        {
            //_length = reader.ReadInt32();
        }

        /// <summary>
        /// Wypisuje pakiet do strumienia wyjsciowego
        /// </summary>
        public void Write(Stream output)
        {
            Write(new BinaryWriter(output));
        }

        public virtual void Write(BinaryWriter writer)
        {
            writer.Write((int)_type);
            writer.Write(_length);
        }

    }
}
